home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)cpit_dsp.c V1.13 3/15/95";
- #endif
-
- /*------------------------------------------------------------------
- | file name -- cpit_dsp.c
- |
- | functions Description
- | --------- -----------
- | InitDisplays Initializes the SCREEN and DRAWPORTS
- | TermDisplays Cleans up the SCREEN, DRAWPORTS and DISPLAY_LIST
- |
- | SwitchDisplay Display Manager
- | OverlayDisplay Overlay the view.
- | RemoveDisplay Deletes the overlayed view.
- |
- | preload_views Preloads all views... (base and overlays)
- | create_drawport Creates the drawport and add is to the table
- | get_drawport Returns the drawport assoiciated with the passed name.
- | load_view Loads the view and adds it to the table.
- | get_view Returns the previously or newly loaded view.
- | next_display Adds a display to the list.
- | prev_display Deletes a display from the list.
- | reset_display Destroys the display list, reset to the top display
- | create_display_list Create a DisplayList for NEXT/PREV.
- | del_display_list_item Delete a display from the DisplayList.
- | destroy_display_list Destroys the DisplayList.
- | update_DynObj_list Creates list for managing dynamic objects.
- |
- |-----------------------------------------------------------------*/
-
- #include "std.h"
- #include "dvstd.h"
- #include "dvGR.h"
- #include "Tfundecl.h"
- #include "VTfundecl.h"
- #include "VOfundecl.h"
- #include "VUerfundecl.h"
- #include "VUfundecl.h"
- #include "GRfundecl.h"
- #include "cpit_vars.h"
- #include "cpit_data.h"
- #include "cpit_fundecl.h"
-
-
-
- #define NEW_LIST (char)0
- #define ADD_TO_LIST (char)1
- #define DELETE_FROM_LIST (char)2
-
- /***************** Begin Function Declarations *************/
- LOCAL void preload_views V_P_((void));
- LOCAL DRAWPORT create_drawport V_P_((OBJECT screen, char *viewname));
- LOCAL DRAWPORT get_drawport V_P_((char *view_name));
- LOCAL VIEW load_view V_P_((char *view_name));
- LOCAL VIEW get_view V_P_((char *view_name));
- LOCAL DRAWPORT next_display V_P_((char *view_name));
- LOCAL DRAWPORT prev_display V_P_((void));
- LOCAL DRAWPORT reset_display V_P_((char *view_name));
- LOCAL DISPLAY_LIST *create_display_list V_P_((void));
- LOCAL void del_display_list_item V_P_((DISPLAY_LIST *display_item));
- LOCAL void destroy_display_list V_P_((DISPLAY_LIST **display_info));
- /***************** End Function Declarations *************/
-
- /*-----------------------------------------------------------------
- |
- | InitDisplays
- | Performs the initialization needed for the display.
- |
- | A SCREEN is opened using DVDEVICE and other attributes.
- |
- | create_drawport() is called to create a drawport for each
- | display area. create_drawport will be called each time a
- | a new views is needed by the display manager.
- */
- void
- InitDisplays (device)
- char *device;
- {
- int error_code;
- char buf[50];
-
- /* Create view and drawport tables needed from display management */
- ViewTable = VTstcreate ("View Names and VIEWs", (VTSTCOMPAREFUNPTR)NULL);
- DpTable = VTstcreate ("View Names and DRAWPORTs", (VTSTCOMPAREFUNPTR)NULL);
-
- /* Open the control window */
- VUoff_copyright ();
- MenuScreen = TscOpenSet (device, (CHAR *) NULL,
- #ifdef WINNT
- V_WINDOW_HEIGHT, 70,
- V_WINDOW_WIDTH, 680,
- V_WINDOW_X, 58,
- V_WINDOW_Y, 0,
- V_WIN32_ICON_NAME, "cpiticon",
- #ifdef DOUBLE_BUFFER
- V_WIN32_DOUBLE_BUFFER, YES,
- #endif /* DOUBLE_BUFFER */
- #else /* Not WINNT */
- V_WINDOW_HEIGHT, 70,
- V_WINDOW_Y, 0,
- V_X_DOUBLE_BUFFER, YES,
- V_X_EXPOSURE_BLOCK, YES,
- #endif /* WINNT */
- V_WINDOW_NAME, "Display Control Panel",
- V_END_OF_LIST );
-
- if(!MenuScreen)
- {
- error_code=TscOpenError();
- #ifdef WINNT
- sprintf(buf,"Product is not validated. Error code %d.",error_code);
- MessageBox(NULL,buf,"Validation Error",MB_OK);
- #else
- fprintf(stderr,"Product is not validated. Error code %d.",error_code);
- #endif
- exit(error_code);
- }
-
- /* If we couldn't open a window, exit the program */
- EXIT_IF_INVALID (MenuScreen, NO_DEVICE);
-
- /* Initialize the window events */
- InitSimpleEvents ();
-
- /* Erase the "copyright" message and set the cursor */
- (VOID) TscErase (MenuScreen);
-
- /* Setup the Menu Screen */
- MenuDrawport = create_drawport (MenuScreen, MENU_VIEW);
- (VOID) TdpDraw (MenuDrawport);
-
- /* Open the main window */
- MainScreen = TscOpenSet (device, (CHAR *) NULL,
- V_WINDOW_NAME, "Aircraft Display",
- #ifdef WINNT
- V_WINDOW_HEIGHT, 465,
- V_WINDOW_WIDTH, 680,
- V_WINDOW_X, 58,
- V_WINDOW_Y, 100,
- V_WIN32_ICON_NAME, "cpiticon",
- #ifdef DOUBLE_BUFFER
- V_WIN32_DOUBLE_BUFFER, YES,
- #endif /* DOUBLE_BUFFER */
- #else /* Not WINNT */
- V_WINDOW_Y, 100,
- V_X_DOUBLE_BUFFER, YES,
- V_X_EXPOSURE_BLOCK, YES,
- #endif /* WINNT */
- V_END_OF_LIST );
-
-
- /* If we couldn't open a window, exit the program */
- EXIT_IF_INVALID (MainScreen, NO_DEVICE);
-
- /* Initialize the window events */
- InitSimpleEvents ();
-
- /* Erase the "copyright" message and set the cursor */
- (VOID) TscErase (MainScreen);
-
- /* Create the a wait drawport */
- SwitchDisplay (NEXT_DISPLAY, WAIT_VIEW);
-
- /* Preload the main views */
- preload_views ();
-
- (VOID) GRset (V_ACTIVE_CURSOR, V_END_OF_LIST);
-
- /* Set the Cursor for the menu screen */
- (VOID) TscSetCurrentScreen (MenuScreen);
- (VOID) GRset (V_ACTIVE_CURSOR, V_END_OF_LIST);
- }
-
- /*-----------------------------------------------------------------
- |
- | SwitchDisplay
- | Switches the view being displayed in the MAIN_WINDOW.
- |
- | The views are managed in a "DisplayList" which is
- | updated according to the "choice".
- | next_display() - Adds a display to the list.
- | prev_display() - Deletes a display from the list.
- |
- | This allows us to keep a history of where we've been.
- |
- | The old display is terminated before the new display is
- | drawn;
- */
- void
- SwitchDisplay (choice, view_name)
- int choice;
- char *view_name;
- {
- DRAWPORT new_dp = NULL;
-
- switch ((INT) choice)
- {
- case PREV_DISPLAY:
- new_dp = prev_display ();
- break;
- case NEXT_DISPLAY:
- new_dp = next_display (view_name);
- break;
- case RESET_DISPLAY:
- new_dp = reset_display (view_name);
- break;
-
- default:
- break;
- }
-
- /* If we can successfully switch displays, cleanup and continue */
- if (new_dp)
- {
- /* Erase the old display */
- (VOID) TdpErase (ActiveDrawport);
- (VOID) TviCloseData (ActiveView);
-
- /* Draw the new display */
- ActiveDrawport = new_dp;
- ActiveView = TdpGetView (ActiveDrawport);
- (VOID) TviOpenData (ActiveView);
- (VOID) TviReadData (ActiveView);
- (VOID) TdpDraw (new_dp);
- }
- }
-
- /*-----------------------------------------------------------------
- |
- | OverlayDisplay
- | Tries to overlay a view to the current display. The
- | named view is merged to the existing drawing.
- |
- */
- void
- OverlayDisplay (view_name)
- char *view_name;
- {
- VIEW overlay_view;
- OBJECT overlay_drawing, overlay_dq, main_dq, test_obj;
- INT i, num_objs;
- DATASOURCELIST main_dsl;
-
- /* Erase the old overlay */
- if (ActiveOverlayName != NULL)
- {
- RemoveDisplay (ActiveOverlayName);
- S_FREE (ActiveOverlayName);
- ActiveOverlayName = NULL;
- }
-
- overlay_view = get_view (view_name);
- if (overlay_view)
- {
- /* Get the overlay drawing and the active view */
- main_dq = VOdrGetObjectDeque (TviGetDrawing (ActiveView));
- overlay_drawing = TviGetDrawing (overlay_view);
- overlay_dq = VOdrGetObjectDeque (overlay_drawing);
-
- /* Test to see if the view has already been overlayed. test
- | can be done by seeing if an object that's in the overlay views
- | is also in the main view. Another way to manage overlays would
- | be to have each drawport/screen keep a list of overlayed views.
- */
- test_obj = VOdqGetEntry (overlay_dq, 1);
- if (!VOdqHasEntry (main_dq, test_obj))
- {
-
- /* Merge the overlay into the active view */
- (VOID) TviMergeDrawing (ActiveView, overlay_drawing);
-
- (VOID) TviCloseData (ActiveView);
- main_dsl = TviGetDataSourceList (ActiveView);
- (VOID) TviMergeAddDataSources (overlay_view, main_dsl, DS_EXACTMATCH);
- (VOID) TviOpenData (ActiveView);
- (VOID) TviReadData (ActiveView);
- }
-
- /* Draw the objects in the overlay view */
- num_objs = VOdqSize (overlay_dq);
- for (i = 1; i <= num_objs; i++)
- (VOID) TdpDrawObject (ActiveDrawport, VOdqGetEntry (overlay_dq, i));
-
- /* Set the active overlay name */
- ActiveOverlayName = StrClone (view_name);
- }
- }
-
- /*-----------------------------------------------------------------
- |
- | RemoveDisplay
- | Tries to delete the named view from the current display. The
- | named view is excised from the existing drawing.
- |
- */
- void
- RemoveDisplay (view_name)
- char *view_name;
- {
- VIEW overlay_view, main_view;
- OBJECT overlay_drawing;
- OBJECT overlay_dq, main_dq, test_obj;
-
- /* Get the overlay drawing and the active view */
- main_view = TdpGetView (ActiveDrawport);
- main_dq = VOdrGetObjectDeque (TviGetDrawing (main_view));
- overlay_view = get_view (view_name);
- overlay_drawing = TviGetDrawing (overlay_view);
- overlay_dq = VOdrGetObjectDeque (overlay_drawing);
-
- /* Test to see if the view has already been overlayed. test
- | can be done by seeing if an object that's in the overlay views
- | is also in the main view. Another way to manage overlays would
- | be to have each drawport/screen keep a list of overlayed views.
- */
- test_obj = VOdqGetEntry (overlay_dq, 1);
-
-
- if (overlay_view && VOdqHasEntry (main_dq, test_obj))
- {
- /* Delete the overlay from the active view */
- (VOID) TviExciseDrawing (main_view, overlay_drawing);
-
- /* We don't need to erase... since in this demo the overlays
- | always take up the same screen space.
- | Normally... you'd erase the excised object and repair the
- | screen below.
- */
- }
- }
-
- /*-----------------------------------------------------------------
- |
- | preload_views
- | The function Pre-Loads the views....of the MAINWINDOW
- */
- LOCAL void preload_views
- V_P_ ((void))
- {
- INT i;
-
- /* For all the room views... load the view, create a drawport, add the
- | drawport to the symbol table.
- */
- for (i = 0; i < NUM_DISPLAYS; i++)
- (VOID) create_drawport (MainScreen, MainViewNames[i]);
- for (i = 0; i < NUM_OVERLAYS; i++)
- (VOID) load_view (OverlayViewNames[i]);
- }
-
- /*-----------------------------------------------------------------
- |
- | create_drawport
- | The function creates a drawport in the specified area to
- | display the specified view.
- |
- | The drawport is added to the symbol tables for easy
- | access by the display manager routines.
- |
- | We call RebindData() for all the dynamic objects. This will
- | see if the variable is being controlled by the application and
- | rebind it if necessary.
- */
- LOCAL DRAWPORT
- create_drawport (screen, viewname)
- OBJECT screen;
- char *viewname;
- {
- VIEW view;
- DRAWPORT drawport = NULL;
- RECTANGLE wvp;
-
- /* Load the view */
- view = TviLoad (viewname);
-
- if (view)
- {
- VOobXformBox (TviGetDrawing (view), (OBJECT)0, &wvp );
-
- drawport = TdpCreateStretch (screen, view, DEFAULT_SIZE, &wvp);
-
- /* Add the drawport to the table */
- (VOID) VTstsninsert (DpTable, StrClone (viewname), (INT *) drawport);
-
- /* Open the Data Sources */
- (VOID) TviOpenData (view);
- (VOID) TviReadData (view);
- }
- return drawport;
- }
-
- /*-----------------------------------------------------------------
- |
- | get_drawport
- | Returns the drawport associated with the view_name. If the
- | drawport doesn't exist, it creates one.
- */
- LOCAL DRAWPORT
- get_drawport (view_name)
- char *view_name;
- {
- SYMNODE key;
-
- /* See if the drawport is already in the Drawport Table */
- key = VTstkeyfind (DpTable, view_name);
- if (key)
- return (DRAWPORT) VTsnvalue (key);
- else
- return create_drawport (MainScreen, view_name);
- }
-
- /*-----------------------------------------------------------------
- |
- | load_view
- | Loads the view and adds it to the View Table. Returns the
- | loaded view. If the view can't be loaded, (TviLoad returned NULL),
- | return NULL.
- */
- LOCAL VIEW
- load_view (view_name)
- char *view_name;
- {
- VIEW view = NULL;
-
- /* Load the view and add it to the table */
- view = TviLoad (view_name);
- if (view)
- {
- (VOID) VTstsninsert (ViewTable, StrClone (view_name), (INT *) view);
- }
-
- return view;
- }
-
- /*-----------------------------------------------------------------
- |
- | get_view
- | Returns the view associated with the view_name. If the
- | view isn't loaded yet, load it and add it to the ViewTable.
- */
- LOCAL VIEW
- get_view (view_name)
- char *view_name;
- {
- SYMNODE key;
- VIEW view;
-
- /* See if the view is already in the Views Table */
- key = VTstkeyfind (ViewTable, view_name);
- if (key)
- return ((VIEW) VTsnvalue (key));
-
- /* The View must not be loaded yet, so load it */
- view = load_view (view_name);
-
- return view;
- }
-
- /*-----------------------------------------------------------------
- |
- | next_display
- | Tries to add a display to the DisplayList. If the view can't
- | be displayed, returns DV_FAILURE, else DV_SUCCESS.
- |
- */
- LOCAL DRAWPORT
- next_display (view_name)
- char *view_name;
- {
- DISPLAY_LIST *prev_display;
- DRAWPORT dp;
-
- /* Get the drawport associated with the view */
- dp = get_drawport (view_name);
- if (dp)
- {
- /* If the list doesn't exist yet, create it.
- |
- | Make the current list top the previous display. Then,
- | make the new display the list top. */
- if (!DisplayList)
- {
- prev_display = create_display_list ();
- prev_display->drawport = ActiveDrawport;
- }
- else
- prev_display = DisplayList;
-
- DisplayList = create_display_list ();
- DisplayList->drawport = dp;
- DisplayList->prev = prev_display;
-
- }
-
- return dp;
- }
-
- /*-----------------------------------------------------------------
- |
- | prev_display
- | If their is a previous display, make it the top and
- | deletes the current from the list.
- */
- LOCAL DRAWPORT prev_display
- V_P_ ((void))
- {
- DISPLAY_LIST *prev_display;
-
- /* Make sure we have a list and a previous display before
- | you make the previous display the top.
- */
- if (DisplayList && DisplayList->prev)
- {
- prev_display = DisplayList->prev;
- del_display_list_item (DisplayList);
- DisplayList = prev_display;
- return DisplayList->drawport;
- }
- else
- return (DRAWPORT) NULL;
- }
-
- /*-----------------------------------------------------------------
- |
- | reset_display
- | Resets the Display List, deletes the previous list and makes
- | the TOP_VIEW the beginning of the list.
- */
- LOCAL DRAWPORT
- reset_display (view_name)
- char *view_name;
- {
-
- /* Destroy the DisplayList */
- destroy_display_list (&DisplayList);
-
- /* return the Active Drawport specified View */
- return get_drawport (view_name);
-
- }
-
- /*-----------------------------------------------------------------
- |
- | create_display_list - Allocates and initializes a DISPLAY_LIST.
- */
- LOCAL DISPLAY_LIST *create_display_list
- V_P_ ((void))
- {
- DISPLAY_LIST *display_info;
-
- display_info = (DISPLAY_LIST *) S_ALLOC ((LONG) sizeof (DISPLAY_LIST));
- display_info->drawport = (DRAWPORT) NULL;
- display_info->prev = (DISPLAY_LIST *) NULL;
- return display_info;
- }
-
- /*-----------------------------------------------------------------
- |
- | del_display_list_item - Frees a DISPLAY_LIST item.
- */
- LOCAL void
- del_display_list_item (display_item)
- DISPLAY_LIST *display_item;
- {
- S_FREE ((CHAR *) display_item);
- }
-
- /*-----------------------------------------------------------------
- |
- | destroy_display_list - Destroys the DISPLAY_LIST by freeing each item.
- */
- LOCAL void
- destroy_display_list (display_info)
- DISPLAY_LIST **display_info;
- {
- DISPLAY_LIST *info, *prev;
-
- info = *display_info;
- while (info)
- {
- prev = info->prev;
- del_display_list_item (info);
- info = prev;
- }
- *display_info = NULL;
- }
-
- /*-----------------------------------------------------------------
- |
- | TermDisplays
- | Performs the termination and clean up needed for the display
- | components. This balances InitDisplays().
- |
- | The Drawport and View Tables are "traversed" to clean up
- | the views and drawports. We also clean up the table as we go.
- | The AreaCoords used to define drawport areas are "freed". The
- | display manager's DisplayList is destroyed. Finally, the screen
- | is erased and closed.
- */
- void TermDisplays
- V_P_ ((void))
- {
- CHAR *viewname;
- SYMNODE node;
- VIEW view;
- DRAWPORT dp;
-
- /* Destroy the display drawports */
- while (VTstlen (DpTable) > 0)
- {
- node = VTstsnget (DpTable, 0);
- viewname = VTsnkey (node);
- S_FREE (viewname);
- dp = (DRAWPORT) VTsnvalue (node);
- view = TdpGetView (dp);
- (VOID) TdpDestroy (dp);
- (VOID) TviDestroy (view);
- VTstsnremove (DpTable, node);
- }
- VTstdestroy (DpTable);
-
- /* Destroy the overlay views */
- while (VTstlen (ViewTable) > 0)
- {
- node = VTstsnget (ViewTable, 0);
- viewname = VTsnkey (node);
- S_FREE (viewname);
- (VOID) TviDestroy ((VIEW) VTsnvalue (node));
- VTstsnremove (ViewTable, node);
- }
- VTstdestroy (ViewTable);
-
- /* Destroy the Display List */
- destroy_display_list (&DisplayList);
-
- /* Destroy, Erase and Close the Main Window */
- (VOID) TscClose (MainScreen);
-
- /* Destroy the Menu Window */
- (VOID) TscClose (MenuScreen);
- }
-
- /*==================================================================
- |
- | StrClone
- | Allocates space for and makes a copy of a specified string,
- | returning a pointer to the string. If there is no input
- | string, the routine returns a NULL.
- */
- CHAR *StrClone( str )
- CHAR *str;
- {
- FAST INT len;
- CHAR *newstr;
- FAST CHAR *to;
- FAST CHAR *from;
-
- if( str == NULL )
- return( NULL );
- len = S_STRLEN( str ) + 1;
- newstr = (CHAR *)S_ALLOC( len );
- if( newstr )
- for( to = newstr, from = str; len > 0; len-- )
- *to++ = *from++;
- return( newstr );
- }
-
-
-